package com.jykj.modbus.equipment.service.guard;

import com.jykj.modbus.equipment.dao.EquipmentDao;
import com.jykj.modbus.equipment.entity.guard.Equipment;
import com.jykj.modbus.equipment.entity.guard.EquipmentMessage;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

public class EquipmentServiceGuard {
    @Resource(name = "equipmentDao")
    public EquipmentDao dao;

    /**************************  基础方法   ***************************/
    /**
     * 保存单条，主要用于新增
     **/
    @Transactional
    public void saveEquipment(Equipment obj) {
        this.dao.saveEquipment(obj);
        //id赋值到设备识别码
        obj.setIdentificationCode(obj.getId());
        this.dao.updateEquipment(obj);
    }

    /**
     * 保存设备报文信息单条，主要用于新增
     * @param obj
     */
    public void saveEquipmentMessage(EquipmentMessage obj){
        this.dao.saveEquipmentMessage(obj);
    }

    /**
     * 查询单条，主要用于新增
     **/
//    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public Equipment getEquipmentOne(Integer id) {
        return this.dao.getEquipmentOne(id);
    }

    /**
     * 修改、更新方法
     */
    @Transactional
    public int updateEquipment(Equipment obj) {
        return this.dao.updateEquipment(obj);
    }

    /**
     * 通过设备识别码删除方法
     **/
    @Transactional
    public void deleteEquipmentByid(Equipment obj) {
        this.dao.deleteEquipmentByid(obj);
        //todo 删除关联指令报文

    }

}
